home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / bildschirmschoner / bserver_v1.5 / sources.lha / Sources / lib / libsources / bitmap_library.c < prev    next >
C/C++ Source or Header  |  1995-10-23  |  5KB  |  182 lines

  1. ; /*
  2.  
  3. sc libcode parms=r streq constlib nostackcheck optimize opttime ignore=73 bitmap_library.c
  4. asm -m2 bitmap_chunky.s
  5. slink LIBFD bitmap.fd TO ///Libs/bitmap.library FROM LIB:libent.o LIB:libinit.o bitmap_library.o bitmap_chunky.o LIB lib:sc.lib libVersion 1 libRevision 4 libid "bitmap 1.4 (10.5.95) Copyright © 1994-1995 by Stefano Reksten" SC SD NOICONS STRIPDEBUG
  6. copy ///Libs/bitmap.library LIBS:
  7. delete bitmap_library.o
  8. delete bitmap_chunky.o
  9. quit
  10.  
  11.  bitmap.library 1.4
  12.  Copyright © 1994-1995 Stefano Reksten of 3AM - The Three Amigos!!!
  13.  All rights reserved.
  14.  
  15. */
  16.  
  17. #include <exec/memory.h>
  18. #include <exec/execbase.h>
  19. #include <intuition/intuition.h>
  20. #include <datatypes/pictureclass.h>
  21. #include <graphics/gfxbase.h>
  22.  
  23. #include <proto/exec.h>
  24. #include <proto/intuition.h>
  25. #include <proto/graphics.h>
  26. /*#include <clib/graphics_protos.h>
  27. #include <pragma/graphics_pragmas.h>*/
  28. #include <proto/dos.h>
  29.  
  30. #include "//include/bitmap/bitmap.h"
  31.  
  32. struct GfxBase *GfxBase;
  33.  
  34. int __saveds __asm __UserLibInit( register __a6 struct MyLibrary *libbase )
  35. {
  36. if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 0L ) )
  37.     return( 0 );
  38. else
  39.     return( 1 );
  40. }
  41.  
  42. void __saveds __asm __UserLibCleanup( register __a6 struct MyLibrary *libbase )
  43. {
  44. CloseLibrary( (struct Library *)GfxBase );
  45. }
  46.  
  47.  
  48. void __asm __saveds DisposeBitMap( register __a1 struct BitMap *bmap )
  49. {
  50. ULONG n;
  51. ULONG plane_size;
  52.  
  53. if ( bmap )
  54.     {
  55.     if ( GfxBase->LibNode.lib_Version >= 39 )
  56.         FreeBitMap( bmap );
  57.     else
  58.         {
  59.         plane_size = bmap->BytesPerRow * bmap->Rows;
  60.  
  61.         for ( n = 0; n < bmap->Depth; n++ )
  62.             {
  63.             if ( bmap->Planes[n] )
  64.                 FreeMem( bmap->Planes[n], plane_size );
  65.             }
  66.         FreeMem( bmap, sizeof(struct BitMap) );
  67.         }
  68.     }
  69. }
  70.  
  71.  
  72. struct BitMap * __asm __saveds CreateBitMap( register __d0 UWORD width, register __d1 UWORD height, register __d2 UBYTE nPlanes )
  73. {
  74. register struct BitMap *bmap;
  75. ULONG plane_size = RASSIZE( width, height );
  76. PLANEPTR planeptr;
  77. ULONG n;
  78.  
  79. if ( GfxBase->LibNode.lib_Version >= 39 )
  80.     return AllocBitMap( width, height, nPlanes, BMF_CLEAR | BMF_STANDARD | BMF_DISPLAYABLE, NULL );
  81. else
  82.     {
  83.     if ( bmap = AllocMem( sizeof(struct BitMap), MEMF_CLEAR ) )
  84.         {
  85.         InitBitMap( bmap, nPlanes, width, height );
  86.  
  87.         for ( n = 0; n < nPlanes; n++ )
  88.             {
  89.             if ( !( planeptr = (PLANEPTR)AllocMem( plane_size, MEMF_CHIP|MEMF_CLEAR ) ) )
  90.                 goto warn;
  91.             bmap->Planes[n] = planeptr;
  92.             }
  93.         return ( bmap );
  94.         }
  95.     warn:
  96.     DisposeBitMap( bmap );
  97.     return( 0L );
  98.     }
  99. }
  100.  
  101.  /**************
  102.  *             *
  103.  * ScaleBitMap *
  104.  *             *
  105.  **************/
  106.  
  107.  
  108. BOOL __asm __saveds ScaleBitMap( register __a1 struct BitMapScaleInfo *scaleinfo )
  109. {
  110. register UWORD StillToGo, CurrentDest, DestXBytes, DestYBytes;
  111. register struct BitMap *TempBitMap;
  112.  
  113. if ( !scaleinfo->bsi_HorDen || !scaleinfo->bsi_VertDen || !scaleinfo->bsi_HorNum || !scaleinfo->bsi_VertNum )
  114.     return( FALSE );
  115.  
  116. if ( !scaleinfo->bsi_TempBitMap )
  117.     {
  118.     if ( !( TempBitMap = CreateBitMap(
  119.         (scaleinfo->bsi_Width + scaleinfo->bsi_HorDen - 1) * scaleinfo->bsi_HorNum / scaleinfo->bsi_HorDen,
  120.         scaleinfo->bsi_Height,
  121.         scaleinfo->bsi_SrcBitMap->Depth ) ) ) return( FALSE );
  122.     }
  123. else
  124.     TempBitMap = scaleinfo->bsi_TempBitMap;
  125.  
  126. DestXBytes = scaleinfo->bsi_Width * scaleinfo->bsi_HorNum / scaleinfo->bsi_HorDen;
  127. DestYBytes = scaleinfo->bsi_Height * scaleinfo->bsi_VertNum / scaleinfo->bsi_VertDen;
  128.  
  129. /* Let's start with columns. */
  130.  
  131. CurrentDest = 0;
  132.  
  133. if ( scaleinfo->bsi_Flags & BSIF_INVERTHOR )
  134.     for ( StillToGo = 0; StillToGo < DestXBytes; StillToGo++ )
  135.         BltBitMap( scaleinfo->bsi_SrcBitMap, scaleinfo->bsi_SrcLeftEdge + ( ( DestXBytes - StillToGo - 1 ) * scaleinfo->bsi_HorDen / scaleinfo->bsi_HorNum ), scaleinfo->bsi_SrcTopEdge,
  136.                 TempBitMap, CurrentDest++, 0,
  137.                 1, scaleinfo->bsi_Height, 0xC0, 0xFF, NULL );
  138. else
  139.     {
  140.     if ( scaleinfo->bsi_HorNum == 1 && scaleinfo->bsi_HorDen == 1 )
  141.         BltBitMap( scaleinfo->bsi_SrcBitMap, scaleinfo->bsi_SrcLeftEdge, scaleinfo->bsi_SrcTopEdge,
  142.                 TempBitMap, 0, 0,
  143.                 scaleinfo->bsi_Width, scaleinfo->bsi_Height, 0xC0, 0xFF, NULL );
  144.     else
  145.         {
  146.         for ( StillToGo = 0; StillToGo < DestXBytes; StillToGo++ )
  147.             BltBitMap( scaleinfo->bsi_SrcBitMap, scaleinfo->bsi_SrcLeftEdge + ( StillToGo * scaleinfo->bsi_HorDen / scaleinfo->bsi_HorNum ), scaleinfo->bsi_SrcTopEdge,
  148.                     TempBitMap, CurrentDest++, 0,
  149.                     1, scaleinfo->bsi_Height, 0xC0, 0xFF, NULL );
  150.         }
  151.     }
  152.  
  153. /* Now, go for the rows. */
  154.  
  155. CurrentDest = scaleinfo->bsi_DestTopEdge;
  156.  
  157. if ( scaleinfo->bsi_Flags & BSIF_INVERTVERT )
  158.     for ( StillToGo = 0; StillToGo < DestYBytes; StillToGo++ )
  159.         BltBitMap( TempBitMap, 0, scaleinfo->bsi_SrcTopEdge + ( ( DestYBytes - StillToGo - 1 ) * scaleinfo->bsi_VertDen / scaleinfo->bsi_VertNum ),
  160.                 scaleinfo->bsi_DestBitMap, scaleinfo->bsi_DestLeftEdge, CurrentDest++,
  161.                 DestXBytes, 1, 0xC0, 0xFF, NULL );
  162. else
  163.     {
  164.     if ( scaleinfo->bsi_VertNum == 1 && scaleinfo->bsi_VertDen == 1 )
  165.         BltBitMap( TempBitMap, 0, 0,
  166.                 scaleinfo->bsi_DestBitMap, scaleinfo->bsi_DestLeftEdge, scaleinfo->bsi_DestTopEdge,
  167.                 DestXBytes, scaleinfo->bsi_Height, 0xC0, 0xFF, NULL );
  168.     else
  169.         {
  170.         for ( StillToGo = 0; StillToGo < DestYBytes; StillToGo++ )
  171.             BltBitMap( TempBitMap, 0, StillToGo * scaleinfo->bsi_VertDen / scaleinfo->bsi_VertNum,
  172.                         scaleinfo->bsi_DestBitMap, scaleinfo->bsi_DestLeftEdge, CurrentDest++,
  173.                         DestXBytes, 1, 0xC0, 0xFF, NULL );
  174.         }
  175.     }
  176.  
  177. if ( scaleinfo->bsi_TempBitMap == 0 )
  178.     DisposeBitMap( TempBitMap );
  179.  
  180. return( TRUE );
  181. }
  182.